import { _decorator, find, Node } from 'cc';
import { BaseLayer } from './BaseLayer';
import { AudioMgr } from '../manager/AudioMgr';
import { ENUM_AUDIO_CLIP, ENUM_GAME_STATUS, ENUM_UI_LAYER } from '../Enum';
import { SdkMgr } from '../manager/SdkMgr';
import { Ins } from '../Ins';
import { DataMgr } from '../manager/DataMgr';
const { ccclass, property } = _decorator;

@ccclass('ExitLayer')
export class ExitLayer extends BaseLayer {
    btn_submit: Node = null
    btn_cancel: Node = null

    onLoad() {
        this.btn_submit = find('panel/main/buttons/btn_submit', this.node)
        this.btn_cancel = find('panel/main/buttons/btn_cancel', this.node)
        this.btn_submit.on('click', this.onSubmitClick, this)
        this.btn_cancel.on('click', this.onCancelClick, this)
    }

    onDestroy() {
        this.btn_submit.off('click', this.onSubmitClick, this)
        this.btn_cancel.off('click', this.onCancelClick, this)
    }

    onEnable() {
        SdkMgr.ins.showInterstitialAd()
    }

    onSubmitClick() {
        AudioMgr.ins.playSound(ENUM_AUDIO_CLIP.CLICK)
        DataMgr.ins.gameStatus = ENUM_GAME_STATUS.UNACTIVE
        Ins.UIMgr.toggle(ENUM_UI_LAYER.MAIN, false)
        Ins.UIMgr.toggle(ENUM_UI_LAYER.EXIT, false)
        Ins.UIMgr.toggle(ENUM_UI_LAYER.MENU)
    }

    onCancelClick() {
        AudioMgr.ins.playSound(ENUM_AUDIO_CLIP.CLICK)
        Ins.UIMgr.toggle(ENUM_UI_LAYER.EXIT, false)
    }
}


